$(function(){
    var getParams = getArgs();
    var currentHotel = getParams.hotel;
    var vipUserId = getParams.no;
    var vipInfoId = getParams.info;
    var color = getParams.cl;
    var payType = getParams.pay;
    window.originalPrice = 0;
    toastr.options = {
        "newestOnTop": false,
        "timeOut": 1500,
        "extendedTimeOut": 0,
        "escapeHtml": true,
        "positionClass": "toast-bottom-center"
    };        
    // 判断是否微信浏览器,进行按钮隐藏
    var isWechatBrowser = function() {
        var ua = navigator.userAgent.toLowerCase();
        if (ua.match(/MicroMessenger/i) == "micromessenger") {
            return true;
        } else {
            return false;
        }
    };
    var requestOrderInfo = function () {
        toggleLoading(true);       
        //后台请求客栈支付信息,判断显示隐藏按钮
        var params = {
            hotelId: currentHotel,
            vipUserId:vipUserId
        };
        ajaxRequest('/Home/Customer/getPayInfo', params, 'POST', function(data) {
            toggleLoading(false);
            window.originalPrice = parseFloat(data.data.cardPrice);
            $('.wechatPayButton').removeClass('hidden');
            $('.aliPayButton').removeClass('hidden');
            if (data.data.wechatpay == '0' || !isWechatBrowser()) {
                $('.wechatPayButton').addClass('hidden');
            }
            if (data.data.alipay == '0') {
                $('.aliPayButton').addClass('hidden');
            }
            var pay = $('#doc .pay:not(.hidden)');
            if(pay.length>0){
                $('#paybtn').removeAttr('disabled');
            } 
            if(payType == 0){
                pay.eq(1).find('.nowrap-content').addClass('check-pay');
            }else{
                pay.eq(0).find('.nowrap-content').addClass('check-pay');
            }
        }, function(error) {
            toggleLoading(false);       
            toastr.error(typeof error.responseJSON === 'undefined' ? lang('tip.server') : error.responseJSON.info);
        });
    };    
    requestOrderInfo();    
    $('#doc').on('click','.pay',function(){
        $(this).find('.nowrap-content').addClass('check-pay');
        $(this).siblings('.pay').find('.nowrap-content').removeClass('check-pay');
    }); 
    var priceContent = $('.horizontal-price-content');
    var getpricetip = function(that){
        that.val(that.val().replace(/[^\?\d.]/g,''));
        var val = that.val();
        if(val != ''){
            val = parseFloat(val)+window.originalPrice;
            priceContent.removeClass('hidden');
            priceContent.find('span').text(val.toFixed(2));
        }else{
            priceContent.addClass('hidden');
            priceContent.find('span').text(window.originalPrice);
        }
    }
    $('#requestRecharge').on("keyup",function(){  
        getpricetip($(this));
    });      
    $('#requestRecharge').on("blur",function(){ 
        getpricetip($(this));
    });  
});
